package com.wzg.appframe.net;

import com.wzg.appframe.utils.TLog;

import org.ksoap2.HeaderProperty;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class WebServiceUtil {
    String url;
    SoapObject request;
    boolean isDotNet;

    public WebServiceUtil(String mUrl, String mNameSpace, String mMethodName, boolean mIsDotNet) {
        this.url = mUrl;
        this.request = new SoapObject(mNameSpace, mMethodName);
        this.isDotNet = mIsDotNet;
    }

    public void addParams(String key, String value) {
        request.addProperty(key, value);
    }

    public String start() throws IOException, XmlPullParserException {
        //创建SoapSerializationEnvelope 对象，同时指定soap版本号(之前在wsdl中看到的)
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapSerializationEnvelope.VER12);
        envelope.bodyOut = this.request;//由于是发送请求，所以是设置bodyOut
        envelope.dotNet = this.isDotNet;//由于是.net开发的webservice，所以这里要设置为true
//        envelope.encodingStyle ="utf-8";


        HttpTransportSE httpTransportSE = new HttpTransportSE(url);


        List<HeaderProperty> list = getHeaders();

        httpTransportSE.call(null, envelope,list);//调用


        // 获取返回的数据
        SoapObject object = (SoapObject) envelope.bodyIn;
        // 获取返回的结果
        String result = object.getProperty(0).toString();
        return result;
    }

    public List<HeaderProperty> getHeaders(){
        List<HeaderProperty> list = new ArrayList<>();

        return list;

    }

}
